<?php

class Model_reference extends CI_Model {
    
    function __construct() {
        parent::__construct();
    }

    public function getReferences() {
        $collection = $this->mongo_db->db->selectCollection('reference');
        $refer = $collection->find();     
        return $refer;
    }

    public function getReference($strId) {
        $id = new MongoId($strId);
        $collection = $this->mongo_db->db->selectCollection('reference');
        $refer = $collection->findOne(array('_id'=> $id));      
        return $refer;
    }
    public function getPlace($strId) {
        $id = new MongoId($strId);
        $collection = $this->mongo_db->db->selectCollection('reference');
        $refer = $collection->findOne(array('_id'=> $id, 'type'=>'place'));      
        return $refer;
    }
    public function getPerson($strId) {
        $id = new MongoId($strId);
        $collection = $this->mongo_db->db->selectCollection('reference');
        $refer = $collection->findOne(array('_id'=> $id, 'type'=>'person'));      
        return $refer;
    }

    public function getPlaces() {
        $collection = $this->mongo_db->db->selectCollection('reference');
        $places = $collection->find(array('type'=>'place'));     
        return $places;
    }
    public function getPersons() {
        $collection = $this->mongo_db->db->selectCollection('reference');
        $places = $collection->find(array('type'=>'person'));     
        return $places;
    }

    // ==========================================================================================

    public function addReference($data) {
        $collection = $this->mongo_db->db->selectCollection('reference');

        $mongoId = new MongoId();
        // $mongoId = (string)$mongoId;
        $data['_id'] = $mongoId;

        $collection->insert($data);
    }

    public function update_reference($data, $id)
    {
        $id = new MongoId($id);
        $collection = $this->mongo_db->db->selectCollection('reference');        
        $collection->update(array('_id' => $id), array('$set' => $data));
    }
}
?>